package com.example.server.web.controller;


import com.example.server.web.domain.RespBean;
import com.example.server.web.domain.StudentQuestionnaire;
import com.example.server.web.domain.page.PageQueryDto;
import com.example.server.web.domain.dto.StuQuestionnaireParamDto;
import com.example.server.web.domain.page.TableDataInfo;
import com.example.server.web.domain.vo.StuQuestionnaireVo;
import com.example.server.web.service.StudentQuestionnaireService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  学生问卷前端控制器
 * </p>
 *
 * @author 作者
 * @since 2023-04-26
 */
@RestController
@RequestMapping("/student-questionnaire")
@Api(tags = {"学生问卷记录接口"})
public class StudentQuestionnaireController {
    @Autowired
    private StudentQuestionnaireService studentQuestionnaireService;

    @PostMapping("/updateLog")
    @ApiOperation("学生填写问卷记录")
    public RespBean updateLog(@RequestBody @Validated StudentQuestionnaire studentQuestionnaire){
        studentQuestionnaireService.updateLog(studentQuestionnaire);
        return RespBean.success("更新成功");
    }

    @GetMapping("/getLog")
    @ApiOperation("查询学生的问卷记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "questionnaireId", value = "问卷id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataTypeClass = Long.class)
    })
    public RespBean getLog(Long questionnaireId, Long userId){
        List<StudentQuestionnaire> log = studentQuestionnaireService.getLog(questionnaireId, userId);
        return RespBean.success("查询成功",log);
    }

    @ApiOperation("根据问卷id查询学生填写问卷记录")
    @GetMapping("/getPageByQnId")
    public TableDataInfo<StuQuestionnaireVo> getPageByQnId(@Validated StuQuestionnaireParamDto paramDto, PageQueryDto pageQueryDto){
        return studentQuestionnaireService.getPageByQnId(paramDto, pageQueryDto);
    }

}
